package com.lex.newbasketball.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lex.newbasketball.R;
import com.lex.newbasketball.entity.MyFriendEntity;
import com.lex.newbasketball.entity.WonderEntity;

import java.util.List;

/**
 * Created by Administrator on 2016/7/28.
 */
public class MyFriendAdapter extends BaseAdapter{
    private Context context;
    private List<MyFriendEntity> myFriendEntityList;

    public MyFriendAdapter(Context context, List<MyFriendEntity> myFriendEntityList ){
        this.context = context;
        this.myFriendEntityList = myFriendEntityList;
    }

    @Override
    public int getCount() {
        return myFriendEntityList.size();
    }

    @Override
    public Object getItem(int i) {
        return myFriendEntityList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    public class ViewHolder{
        private ImageView head, picture;
        private TextView name, address, time, type, feel;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        MyFriendEntity myFriendEntity = myFriendEntityList.get(i);
        ViewHolder viewHolder = null;
        if (viewHolder == null) {
            convertView = convertView.inflate(context, R.layout.item_my_friends_item, null);
            viewHolder = new ViewHolder();
            viewHolder.head = (ImageView) convertView.findViewById(R.id.my_head);
            viewHolder.picture = (ImageView) convertView.findViewById(R.id.my_picture);
            viewHolder.name = (TextView) convertView.findViewById(R.id.my_name);
            viewHolder.address = (TextView) convertView.findViewById(R.id.my_address);
            viewHolder.time = (TextView) convertView.findViewById(R.id.my_time);
            viewHolder.type = (TextView) convertView.findViewById(R.id.my_type);
            viewHolder.feel = (TextView) convertView.findViewById(R.id.my_feel);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.head.setImageResource(myFriendEntity.getHead());
        viewHolder.picture.setImageResource(myFriendEntity.getPicture());
        viewHolder.name.setText(myFriendEntity.getName());
        viewHolder.address.setText(myFriendEntity.getAddress());
        viewHolder.time.setText(myFriendEntity.getTime());
        viewHolder.type.setText(myFriendEntity.getType());
        viewHolder.feel.setText(myFriendEntity.getFeel());
        return convertView;
    }
}
